<html>
<head>
<link rel="stylesheet" href='../css/sh/SyntaxHighlighter.css' type="text/css" />
<script src='../js/sh/shCore.js'></script>
<script src='../js/sh/shBrushJava.js'></script>
<style>

* {
font-family:Courier New,monospace;
  padding: 0;
  margin: 0;
  white-space: nowrap;
  font-size: 11px;
}

.dp-highlighter {
  white-space: nowrap;
  overflow: visible;
  width: 700px;
  font-size: 11px;
  font-family:Courier New,monospace;
}
</style>
</head>
<body>
<textarea name="code" class="java:nogutter:nocontrols" rows="15" cols="120">/**
 * Test case to demonstrate View Source functionality for Component Assistant
 * without plainPanels and menu 
 * 
 * @classname OWT_317b
 * @author Sonia Ratta
 * @version 1.0 30-Sept-2009
 */
package com.ssc.osawt.junit.workspace.client;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.SimpleStore;
import com.gwtext.client.data.Store;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Toolbar;
import com.gwtext.client.widgets.ToolbarTextItem;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.Field;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
import com.gwtext.client.widgets.grid.GridView;
import com.gwtext.client.widgets.menu.Menu;
import com.ssc.osa.osawt.workspace.client.ComponentAssistant;
import com.ssc.osa.osawt.workspace.client.GridPanel;
import com.ssc.osa.osawt.workspace.client.auth.MCH;
import com.ssc.osa.osawt.workspace.client.core.IntrefOutput;
import com.ssc.osa.osawt.workspace.client.core.IntrefParam;

public class OWT_317b extends ComponentAssistant
{
    private GridPanel grdFundPanel;
    private IntrefParam expParams[];
    private IntrefOutput expOutputs[];
    private ComboBox cmbFund;

    public OWT_317b()
    {
	super(new MCH(),true,false,false);
	setEastPanelVisible(false);
	setWestPanelVisible(false);
	setSouthPanelVisible(false);

	addSourceCode("com.ssc.osawt.junit.workspace.client.OWT_317b");
	addSourceCode("com.ssc.osawt.junit.ehorizon.grid.client.OWT_99");
    }

    public Panel getComponent()
    {
	expOutputs = new IntrefOutput[]	{ 
		new IntrefOutput("Fund", "FUND", String.class, 70),
		new IntrefOutput("Fund Ext", "FUND_EXT", String.class, 70),
		new IntrefOutput("Cusip", "CUSIP", String.class, 100),
		new IntrefOutput("Maturity Date", "MAT_DATE", Date.class, 100),
		new IntrefOutput("Recon Run Date", "RECON_RUN_DATE", Date.class,
			100, null, "Y-n-j", "MMM dd, yyyy"),
		new IntrefOutput("Date Of Difference", "DATE_OF_DIFFERENCE", 
			Date.class, 120, null, null, "MM/dd/yyyy"),
		new IntrefOutput("Run Date Time", "RUN_DATE_TIME", Date.class,
			150, null, "Ynj H:i:s", "MMM dd, yyyy HH:mm:ss a"),
		new IntrefOutput("Acct Trade Date Pos", "ACCT_TRD_DTE_POS",
			Double.class, 150),
		new IntrefOutput("Acct Net Pnd Pos", "ACCT_NET_PND_POS",
			Double.class, 120),
		new IntrefOutput("SMAC ISMAC STL Pos", "SMAC_ISMAC_STL_POS",
			Double.class, 130),
		new IntrefOutput("Acct Rest Pos", "ACCT_REST_POS", Double.class, 100),
		new IntrefOutput("STL Control Unit", "STL_CONTROL_UNIT",
			Double.class, 120),
		new IntrefOutput("SW Pnd Activity", "SW_PND_ACTIVITY",
			String.class, 100),
		new IntrefOutput("Division", "DIVISION", String.class, 100),
		new IntrefOutput("Country", "COUNTRY", String.class, 100),
		new IntrefOutput("Exception Status", "EXCEPTION_STATUS",
			String.class, 150) };

	int enablePag = GridPanel.PAGINATION | GridPanel.FILTER 
		| GridPanel.SORT | GridPanel.EXCEL_EXPORT;
	grdFundPanel = new GridPanel(expOutputs, 1000, 295, enablePag, 25);
	grdFundPanel.setTitle("OWT-317b");
	grdFundPanel.setBorder(false);
	grdFundPanel.setId("grdFundPanel");
	grdFundPanel.setAutoScroll(true);
	
	GridView view = new GridView();
	view.setEnableRowBody(true);
	grdFundPanel.setView(view);

	grdFundPanel.setTopToolbar(new InputToolBar());
	onSearch();
	return grdFundPanel;
    }

    public class InputToolBar extends Toolbar
    {
	public InputToolBar()
	{
	    setPosition(0, 0);

	    Menu menu = new Menu();
	    menu.setShadow(true);

	    ToolbarTextItem lblFund = new ToolbarTextItem("Fund:");
	    lblFund.setWidth("50");
	    addItem(lblFund);

	    final Store store = new SimpleStore(new String[]
	    { "id", "text" }, getFundValues());
	    store.load();

	    cmbFund = new ComboBox();
	    cmbFund.setForceSelection(true);
	    cmbFund.setMinChars(1);
	    cmbFund.setFieldLabel("id");
	    cmbFund.setStore(store);
	    cmbFund.setDisplayField("text");
	    cmbFund.setMode(ComboBox.LOCAL);
	    cmbFund.setTriggerAction(ComboBox.ALL);
	    cmbFund.setTypeAhead(true);
	    cmbFund.setSelectOnFocus(true);
	    cmbFund.setWidth(100);

	    cmbFund.setHideTrigger(false);
	    cmbFund.setValue("AAA1");

	    cmbFund.addListener(new CmbListener());

	    addElement(cmbFund.getElement());
	}
    }

    public String[][] getFundValues()
    {
	String[][] data = new String[][] {
	{ "AAA1", "AAA1" },
	{ "AAA2", "AAA2" },
	{ "AAA3", "AAA3" },
	{ "AAA4", "AAA4" },
	{ "AAA5", "AAA5" },
	{ "AAA6", "AAA6" } };
	return data;
    }

    public class CmbListener extends ComboBoxListenerAdapter
    {
	public void onSelect(ComboBox comboBox, Record record, int index)
	{
	    GWT.log("ComboBox::onSelect('" + record.getAsString("text") + "')", null);
	    onSearch();
	}

	public void onChange(Field field, Object newVal, Object oldVal)
	{
	    GWT.log("changed", null);
	}

	public void onBlur(Field field)
	{
	    GWT.log("onBlur", null);
	}
    }

    public void onSearch()
    {
	if (cmbFund.isValid() && cmbFund.getText().length() == 4)
	{
	    expParams = new IntrefParam[] {
		    new IntrefParam("__request", "2599070"),
		    new IntrefParam("FUND", cmbFund.getText().toUpperCase()) };

	    grdFundPanel.load(expParams);
	}
    }
}
</textarea>
<script class="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
</body>
</html>